class Solution {//leeetcode978——最长湍流子数组
public:
    int maxTurbulenceSize(vector<int>& arr) {
        int n=arr.size();
        vector<int> f(n,1);//f[i]最后呈上升的湍流子数组
        vector<int> g(n,1);
        int ret=1;
        for(int i=1;i<n;i++){
            if(arr[i]>arr[i-1]) f[i]=g[i-1]+1;
            if(arr[i]<arr[i-1]) g[i]=f[i-1]+1;
            ret=max(ret,max(f[i],g[i]));
        }
        return ret;
    }
};